import {
  request,
  BASEURL
} from '../../utils/request';
Page({
  data: {
    index: 1,
    orderList: [],
    show: false,
    thumbUrl:getApp().globalData.thumbUrl
  },

  onLoad: function (options) {
    //获取订单页面数据
    this.orderList()
    console.log(options)
    this.setData({
      index: options.index
    })
  },
  onShow: function () {
    //获取订单页面数据
    this.orderList()
  },

  //请求订单页面数据
  async orderList() {
    var that = this
    console.log(that.data.index)
    let {
      openid
    } = wx.getStorageSync('uid')
    let res = await request({
      url: '/api/Wxapp/myorder',
      method: "POST",
      data: {
        status: this.data.index,
        openid
      }
    })
    console.log(res)
    if(res.data.code==1){
      this.setData({
        orderList: res.data.data,
        show:true
      })
    }else{
      this.setData({
        show:false
      })
    }

  },

  //确认收货
  async affirm(e) {
    console.log(e)
    let index = e.currentTarget.dataset.id
    console.log(index)
    // openid   oid(订单id)
    let {
      openid
    } = wx.getStorageSync('uid')
    let oid = this.data.orderList[index].id
    console.log(oid)
    let res = await request({
      url: '/api/Wxapp/confirmeOrder',
      method: "POST",
      data: {
        openid,
        oid
      }
    })
    // 刷新页面
    this.orderList()
  },

  //切换
  tabIndex: function (e) {
    console.log(e)
    this.setData({
      index: e.currentTarget.dataset.index
    })
    this.orderList()
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})